<?php
class ValueAction extends Action {
public function ckfinder(){

	header('Location: http://localhost/ivyproject/Public/ckfinder/ckfinder.html');
	//header('Location: http://ivycapital2012.eicp.net:8080/ivyproject/public/ckfinder/ckfinder.html/');
}
public function showindustry() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "indid desc";
		}

		
		$Dao = D("industry");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
public function showproject() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "state desc";
		}

		
		$Dao = D("project");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
public function showcompanyfinance() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "project_pid desc";
		}

		
		$Dao = D("Company_finance");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> relation(true)->order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();
		
		

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
	public function showtracking() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "project_pid desc";
		}

		
		$Dao = D("Info_tracking");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> relation(true)->order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();
		
		

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
	public function showaddition() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "project_pid desc";
		}

		
		$Dao = D("additionservice");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> relation(true)->order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();
		
		

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
	public function showinvest() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "project_pid desc";
		}

		
		$Dao = D("investchange");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> relation(true)->order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();
		
		

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
	
	public function test() {
	
		
header("Content-Type:text/html; charset=utf-8");
		$Invest=D("Investchange");
		
		$funds=$Invest->field('project_pid,investor')->group('project_pid,investor')->select();
		dump($funds);
		//$fundarray== array();
		
		foreach ($funds as $id => $data) {
			if($fundarray[$data['project_pid']])
			$fundarray[$data['project_pid']]=$fundarray[$data['project_pid']].','.$data['investor'];			
			else
			$fundarray[$data['project_pid']]=$data['investor'];			
		}
		dump($fundarray);
		
		$Dao = D("ProjectView");
		
		$total = $Dao->count ();
		//dump($total);
		$list = $Dao->select();
	
		$result = array();
		foreach ($list as $id => $data) {
			$data["postfund"]=$fundarray[$data['pid']];
			array_push($result, $data);			
		}
		dump($result);
		// $resultData = array("total"=>$total,"data"=>$result);

		// $Data=json_encode($resultData);
		// dump($Data);
		// print_r($Data);
		
		//dump($list);
		

	}
public function showfund() {
		

		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "funid desc";
		}

		
		$Dao = D("fund");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}

	public function showuser() {
		
		$condition ['nickname'] = array ('like', '%' . $_REQUEST["key"] . '%' );
		
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "uid desc";
		}

		
		$Dao = D("User");

		$total = $Dao->where($condition) -> count();

		//dump($total);
		$list = $Dao ->where($condition)-> order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
public function showmeeting() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "idmeetinglog desc";
		}

		
		$Dao = D("Meetinglog");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}
public function showmail() {
	
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];

		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];

		if (!empty($sortField)) {
			if ($sortOrder != "desc")
				$sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		} else {
			$order = "mid desc";
		}

		
		$Dao = D("Mail");

		$total = $Dao->where() -> count();

		//dump($total);
		$list = $Dao -> order($order) -> limit($pageIndex * $pageSize . ',' . $pageSize) -> select();

		$resultData = array("total" => $total, "data" => $list);

		
		$Data = json_encode($resultData);
		print_r($Data);

	}

public function SaveIndustry() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("industry");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			$ind->industry=$row["industry"];
			$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['indid']=$row["indid"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
			//$testDB->UpdateIndustry($row);
			$condition['indid']=$row["indid"];
			$ind->where($condition)->delete();
			$ind->industry=$row["industry"];
			$ind->add();
        	
}
}
}
public function SaveMeeting() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("Meetinglog");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			$ind->date=$row["date"];
			$ind->content=$row["content"];
			$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['idmeetinglog']=$row["idmeetinglog"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
        	//$testDB->UpdateIndustry($row);
			$condition['idmeetinglog']=$row["idmeetinglog"];	
			$newinfo->date=$row["date"];
			$newinfo->content=$row["content"];
			$ind->where($condition)->save($newinfo);
			    	
}
}
}
public function SaveProject() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("project");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			//$ind->date=$row["date"];
			//$ind->content=$row["content"];
			//$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['pid']=$row["pid"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
        	//$testDB->UpdateIndustry($row);
			$condition['pid']=$row["pid"];	
			$newinfo->pno=$row["pno"];
			$newinfo->pname=$row["pname"];
			$newinfo->regdate=$row["regdate"];
			$newinfo->state=$row["state"];
			$ind->where($condition)->save($newinfo);
			//$this->sendmessage("系统管理员修改了您的信息！",$row["nickname"]);    
			    	
}
}
}
public function SaveCompanyfinance() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("Company_finance");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			//$ind->date=$row["date"];
			//$ind->content=$row["content"];
			//$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['idcompany_finance']=$row["idcompany_finance"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
        	//$testDB->UpdateIndustry($row);
			$condition['idcompany_finance']=$row["idcompany_finance"];	
			$newinfo->income=$row["income"];
			$newinfo->net_income=$row["net_income"];
			$newinfo->EBITDA=$row["EBITDA"];
			$newinfo->EBIT=$row["EBIT"];
			$ind->where($condition)->save($newinfo);
			//$this->sendmessage("系统管理员修改了您的信息！",$row["nickname"]);    
			    	
}
}
}
public function SaveInvest() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("Investchange");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			//$ind->date=$row["date"];
			//$ind->content=$row["content"];
			//$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['icid']=$row["icid"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
        	//$testDB->UpdateIndustry($row);
			$condition['icid']=$row["icid"];	
			$newinfo->investor=$row["investor"];
			$newinfo->investnum=$row["investnum"];
			$newinfo->date=$row["date"];
			$newinfo->reason=$row["reason"];
			$newinfo->header=$row["header"];
			$newinfo->maininvestor=$row["maininvestor"];
			$ind->where($condition)->save($newinfo);
			//$this->sendmessage("系统管理员修改了您的信息！",$row["nickname"]);    
			    	
}
}
}
public function SaveTracking() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("Info_tracking");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			//$ind->date=$row["date"];
			//$ind->content=$row["content"];
			//$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['idinfo_tracking']=$row["idinfo_tracking"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
        	//$testDB->UpdateIndustry($row);
			$condition['idinfo_tracking']=$row["idinfo_tracking"];	
			$newinfo->date=$row["date"];
			$newinfo->info=$row["info"];
			$newinfo->determine=$row["determine"];		
			$ind->where($condition)->save($newinfo);
			//$this->sendmessage("系统管理员修改了您的信息！",$row["nickname"]);    
			    	
}
}
}
public function SaveAddition() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("additionservice");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			//$ind->date=$row["date"];
			//$ind->content=$row["content"];
			//$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['idadditionservice']=$row["idadditionservice"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
        	//$testDB->UpdateIndustry($row);
			$condition['idadditionservice']=$row["idadditionservice"];	
			$newinfo->date=$row["date"];
			$newinfo->type=$row["type"];
			$newinfo->content=$row["content"];		
			$ind->where($condition)->save($newinfo);
			//$this->sendmessage("系统管理员修改了您的信息！",$row["nickname"]);    
			    	
}
}
}
public function SaveFund() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("fund");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			$ind->fund=$row["fund"];
			$ind->add();
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['funid']=$row["funid"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
			//$testDB->UpdateIndustry($row);
			$condition['funid']=$row["funid"];
			$ind->where($condition)->delete();
			$ind->fund=$row["fund"];
			$ind->add();
        	
}
}
}
public function SaveUser() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("User");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			$ind->username=$row["username"];
			$ind->password=MD5($row["username"]);
			$ind->nickname=$row["nickname"];
			$ind->depart=$row["depart"];
			$ind->position=$row["position"];
			$ind->add();
			$this->sendmessage("默认密码与登陆名相同，请及时修改！ 若需修改所属部门，请联系管理员！",$row["nickname"]);
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['uid']=$row["uid"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
			//$testDB->UpdateIndustry($row);
			$condition['uid']=$row["uid"];	
			$newinfo->username=$row["username"];
			$newinfo->nickname=$row["nickname"];
			$newinfo->depart=$row["depart"];
			$newinfo->position=$row["position"];
			$ind->where($condition)->save($newinfo);
			$this->sendmessage("系统管理员修改了您的信息！",$row["nickname"]);     	
}
}
}
public function SaveMail() {
		$json = $_REQUEST["data"];
		$stripStr = stripslashes($json);
	    $rows = json_decode($stripStr,true);
	    $ind=D("Mail");
	    foreach ($rows as $row){
    	$state = $row["_state"] != null?$row["_state"]:"";    
		if($state == "added" ){ //新增：id为空，或_state为added
			//$row["createtime"] = date("Y-m-d   h:i:s");
			//$testDB->InsertIndustry($row);
			$ind->sendname=$row["sendname"];
			$ind->getname=$row["getname"];
			$ind->title=$row["title"];
			$ind->senddate=$row["senddate"];
			$ind->content=$row["content"];
			$ind->state=$row["state"];
			$ind->add();
		
		}
		else if ($state == "removed" || $state == "deleted")
   	    {
	 		//$testDB->DeleteIndustry($row["industry"]);
	 		$condition['mid']=$row["mid"];
	 		$ind->where($condition)->delete();
   	    }
		else if ($state == "modified" || $state)  //更新：_state为空或modified
        {
			//$testDB->UpdateIndustry($row);
			$condition['mid']=$row["mid"];	
			$ind->sendname=$row["sendname"];
			$ind->getname=$row["getname"];
			$ind->title=$row["title"];
			$ind->senddate=$row["senddate"];
			$ind->content=$row["content"];
			$ind->state=$row["state"];
			$ind->where($condition)->save($newinfo);
		
}
}
}
public function sendmessage($message,$getname){
		$Dao=D("Mail");
		$Data['sendname']="系统管理员";
		$Data['getname']=$getname;
		$Data['senddate']=date('Y-m-d');
		$Data['content']=$message;
		$Data['title']="系统消息";
		
		$Dao->add($Data);		
			
	}
}